﻿#include "loadsysinfodata.h"

#include "LoadData/loadsysinfodata.h"
#include <QFile>
#include <QTextStream>
#include <QFileInfo>

LoadSysInfoData::LoadSysInfoData(void)
{
    sysInfoDatas.clear();
    bLoadData = false;
}


LoadSysInfoData::~LoadSysInfoData(void)
{

}


//文件夹路径strFilePath
bool LoadSysInfoData::LoadFile(QString strFilePath)
{


    QFile file(strFilePath);
    if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        bLoadData = false;
        return bLoadData;
    }

    QTextStream stream(&file);

    int lineDataNum=8;
    while(!stream.atEnd())
    {
        QString line = stream.readLine();  // 读取一行数据
        if(line.isEmpty())
            continue;  // 跳过空行

        QStringList fields = line.split(',');  // 使用逗号分割字符串

        if(fields.size() < lineDataNum)
            continue;  // 如果分割后的数据少于5个，跳过此行

        std::vector<double> data;
        //读取每一行的数据
        for(QString field : fields)
        {
            data.push_back(field.trimmed().toDouble());  // 去除前后空格后转换为double
        }
        //创建一个对象存储
        SimSystemInfo dataLine(data[0],data[1],data[2],
                data[3],data[4],data[5],
                data[6],data[7]
                );

        sysInfoDatas.push_back(dataLine);
    }

    bLoadData = true;
    return bLoadData;
}


//清除数据
void LoadSysInfoData::ClearData()
{
    sysInfoDatas.clear();
    bLoadData = false;
}

std::vector<SimSystemInfo> LoadSysInfoData::getSysInfoDatas() const
{
    return sysInfoDatas;
}

void LoadSysInfoData::setSysInfoDatas(const std::vector<SimSystemInfo> &value)
{
    sysInfoDatas = value;
}
